﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using System.Text;
using ZX.SYS.Bussiness.Message;
using ZX.SYS.Library;
namespace ZX.WebApp.Crm
{
    public partial class ShowMessage :BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ShowMsg();
        }
        #region 显示发送给我的消息
        private void ShowMsg()
        {
            string id = this.GetStringFromQueryString("ID", "");
            string state = this.GetStringFromQueryString("state", "");

            GetMessageList(id);
            //标识消息为已读
            if (state == "3")
            {
                BDatMessagePool msgMrg = new BDatMessagePool();
                msgMrg.setSendState(new Guid(id));
            }
        }
        /// <summary>
        /// 得到消息详细信息
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private void GetMessageList(string msgId)
        {

            string state = this.GetStringFromQueryString("state", "");
            if (state == "0" || state == "3")
            {
                //未查看
                BV_MessagePool messageMrg1 = new BV_MessagePool();
                int i = 0;
                if (state == "3")
                {
                    ZX.SYS.Library.V_MessagePool message = (ZX.SYS.Library.V_MessagePool)messageMrg1.GetEntityById(msgId);
                    if (message != null)
                    {
                        Lb_Name.Text = string.Format("<font color=\"#999999\">{0}</font>", message.AddUserName);//显示发送人姓名
                        Lb_Content.Text = message.MsgContent;//显示发送内容
                        string sendTime = string.Format("<font color=\"#999999\">{0}</font>", message.SendTime.ToString("yyyy-MM-dd"));
                        Lb_Time.Text = sendTime;        //显示发送时间
                        //显示消息类型
                        string type = "";
                        switch (message.MessageType)
                        {
                            case "0": type = "系统消息";
                                break;
                            case "1": type = "Email";
                                break;
                            case "2": type = "手机短信";
                                break;
                            case "3": type = "QQ";
                                break;
                        }
                        lblMessageType.Text = string.Format("<font color=\"#999999\">{0}</font>", type);
                        LblSubject.Text = string.Format("<font color=\"#999999\">{0}</font>", message.Title);//信息主题
                    }
                }
                else
                {
                    ZX.SYS.Library.V_MessagePool message = (ZX.SYS.Library.V_MessagePool)messageMrg1.GetEntityById(msgId);
                    if (message != null)
                    {
                        Lb_Name.Text = string.Format("<font color=\"#999999\">{0}</font>", message.AddUserName);//显示发送人姓名
                        Lb_Content.Text = message.MsgContent;//显示发送内容
                        string sendTime = string.Format("<font color=\"#999999\">{0}</font>", message.SendTime.ToString("yyyy-MM-dd"));
                        Lb_Time.Text = sendTime;        //显示发送时间
                        //显示消息类型
                        string type = "";
                        switch (message.MessageType)
                        {
                            case "0": type = "系统消息";
                                break;
                            case "1": type = "Email";
                                break;
                            case "2": type = "手机短信";
                                break;
                            case "3": type = "QQ";
                                break;
                        }
                        lblMessageType.Text = string.Format("<font color=\"#999999\">{0}</font>", type);
                        LblSubject.Text = string.Format("<font color=\"#999999\">{0}</font>", message.Title);//信息主题
                    }
                }
            }
            else if (state == "1")
            {
                //已查看
                BV_HistoryMessagePool target = new BV_HistoryMessagePool(); // TODO: 初始化为适当的值
                ZX.SYS.Library.V_HistoryMessagePool message = (ZX.SYS.Library.V_HistoryMessagePool)target.GetEntityById(msgId);

                if (message != null)
                {
                    Lb_Name.Text = string.Format("<font color=\"#999999\">{0}</font>", message.AddUserName);//显示发送人姓名
                    Lb_Content.Text = message.MsgContent;//显示发送内容
                    string sendTime = string.Format("<font color=\"#999999\">{0}</font>", message.SendTime.ToString("yyyy-MM-dd"));
                    Lb_Time.Text = sendTime;        //显示发送时间
                    //显示消息类型
                    string type = "";
                    switch (message.MessageType)
                    {
                        case "0": type = "系统消息";
                            break;
                        case "1": type = "Email";
                            break;
                        case "2": type = "手机短信";
                            break;
                        case "3": type = "QQ";
                            break;
                    }
                    lblMessageType.Text = string.Format("<font color=\"#999999\">{0}</font>", type);
                    LblSubject.Text = string.Format("<font color=\"#999999\">{0}</font>", message.Title);//信息主题
                }

            }
            else if (state == "")
            {
                //全部
                BV_AllMessage target = new BV_AllMessage(); // TODO: 初始化为适当的值
                ZX.SYS.Library.V_AllMessage message = (ZX.SYS.Library.V_AllMessage)target.GetEntityById(msgId);
                if (message != null)
                {
                    Lb_Name.Text = string.Format("<font color=\"#999999\">{0}</font>", message.AddUserName);//显示发送人姓名
                    Lb_Content.Text = message.MsgContent;//显示发送内容
                    string sendTime = string.Format("<font color=\"#999999\">{0}</font>", message.SendTime.ToString("yyyy-MM-dd"));
                    Lb_Time.Text = sendTime;        //显示发送时间
                    //显示消息类型
                    string type = "";
                    switch (message.MessageType)
                    {
                        case "0": type = "系统消息";
                            break;
                        case "1": type = "Email";
                            break;
                        case "2": type = "手机短信";
                            break;
                        case "3": type = "QQ";
                            break;
                    }
                    lblMessageType.Text = string.Format("<font color=\"#999999\">{0}</font>", type);
                    LblSubject.Text = string.Format("<font color=\"#999999\">{0}</font>", message.Title);//信息主题
                }
              

            }

        }
        #endregion
    }
}